package org.elip.stewiemaze.server.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtils {
	
	public static Cookie getCookie(HttpServletRequest req, String cookieName) {
		Cookie[] cookies = req.getCookies();
		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().equals(cookieName)) {
					return c;
				}
			}
		}
		return null;
	}
	
	public static void eraseCookie(HttpServletRequest req, HttpServletResponse res,String cookieName) {
		Cookie cookie = getCookie(req, cookieName);
		cookie.setMaxAge(0);
		res.addCookie(cookie);
	}

}
